
#ifndef	__DIRECTSOUND_INCLUDED__
#define	__DIRECTSOUND_INCLUDED__

#define	WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <mmsystem.h>

#define DIRECTSOUND_VERSION	0x0700
#include <dsound.h>



#include "typedef.h"
#include "macro.h"



class	CDirectSound
{
public:
	
	typedef	struct	tagSAMPLERATE {
		DWORD	Rate;
		DWORD	Bits;
	} SAMPLERATE, *LPSAMPLERATE;

	SAMPLERATE		m_SampleRate;		
	INT			m_BufferSize;		
	static	SAMPLERATE	m_SampleRateTable[];	
	static	INT		m_BufferSizeTable[];	

	
	CDirectSound();
	virtual ~CDirectSound();

	BOOL	InitialDSound( HWND hWnd );
	void	ReleaseDSound();

	BOOL	InitialBuffer();
	void	ReleaseBuffer();

	BOOL	SetSamplingRate( DWORD rate, DWORD bits );
	void	GetSamplingRate( DWORD& rate, DWORD& bits );

	void	SetBufferSize( INT nSize ) { m_BufferSize = nSize; }
	INT	GetBufferSize()		   { return m_BufferSize; }

	BOOL	IsStreamPlaying() { return (m_bStreamPlay&&!m_bStreamPause); }
	void	StreamPlay();
	void	StreamStop();
	void	StreamPause();
	void	StreamResume();

	BOOL	GetStreamLockPosition( LPDWORD lpdwStart, LPDWORD lpdwSize );
	BOOL	StreamLock( DWORD dwWriteCursor, DWORD dwWriteBytes, LPVOID* lplpvPtr1, LPDWORD lpdwBytes1, LPVOID* lplpvPtr2, LPDWORD lpdwBytes2, DWORD dwFlags );
	BOOL	StreamUnlock( LPVOID lpvPtr1, DWORD dwBytes1, LPVOID lpvPtr2, DWORD dwBytes2 );

	BOOL	IsStreamPlay() { return m_bStreamPlay; }
	BOOL	IsStreamPause() { return m_bStreamPause; }

	

protected:

	HWND	m_hWnd;		// Window handle

	LPDIRECTSOUND		m_lpDS;		
	LPDIRECTSOUNDBUFFER	m_lpDSPrimary;	

	LPDIRECTSOUNDBUFFER	m_lpDSStream;		

	DWORD			m_dwDSBufferSize;
	DWORD			m_dwDSBlockSize;	
	DWORD			m_dwDSBlockNum;		
	DWORD			m_dwDSLastBlock;	

	volatile BOOL		m_bStreamPlay;	
	volatile BOOL		m_bStreamPause;	




private:

};

extern	CDirectSound	DirectSound;

#endif	// !__DIRECTSOUND_INCLUDED__
